//
//  AddTalkingViewController.m
//  TeacherNet
//
//  Created by slz on 2017/12/12.
//  Copyright © 2017年 bnsr. All rights reserved.
//

#import "AddTalkingViewController.h"
#import <IQKeyboardManager.h>

@interface AddTalkingViewController ()
@property (weak, nonatomic) IBOutlet UITextField *titleTextFiled;
@property (weak, nonatomic) IBOutlet UITextView *contentTextView;

@end

@implementation AddTalkingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    [IQKeyboardManager sharedManager].keyboardDistanceFromTextField = 100;

    self.showNavigationBar = YES;
    [self setControllerTitle:@"添加问答"];
    UIBarButtonItem * backItem = [UIBarButtonItem itemWithImage:@"back_icon" selectImage:@"" addTarget:self andAction:@selector(backAction)];
    self.navigationItem.leftBarButtonItem = backItem;
    // Do any additional setup after loading the view from its nib.
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)addAction:(id)sender {
    NSString * title = self.titleTextFiled.text;
    if (title.length <=0){
        [self.view showTip:@"请输入标题~"];
        return;
    }
    NSString * content = self.contentTextView.text;
    if (content.length <=0){
        [self.view showTip:@"请输入内容~"];
        return;
    }
    [SVProgressHUD showWithStatus:@"发布中..."];
    [BaseHttpTool get:kAPI_COURSE_ADD_TALKING params:@{@"class_id":self.classId,@"source_type":@"0",@"source_id":self.courseId,@"user_id":[MFWSdkEnvironment sharedInstance].userInfo.uid,@"title":self.titleTextFiled.text,@"question _content":self.contentTextView.text} success:^(id responseObj) {
        [SVProgressHUD showSuccessWithStatus:@"发布成功~"];
        if (self.completion){
            self.completion(YES);
        }
        [self.navigationController popViewControllerAnimated:YES];
        NSLog(@"%@",responseObj);
    } failure:^(NSError *error) {
        [SVProgressHUD showSuccessWithStatus:@"发布失败~"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
